package com.fys.markbook.util

import java.sql.Connection
import java.sql.DriverManager
import java.sql.SQLException
import java.util.*

/**
 * @Title:
 * @Description:
 * @Author: fanyushuai
 * @Date: 2023/9/6 14:41
 * @Version V1.0
 */
object JDBCUtil {
    var conn: Connection? = null

    @get:Throws(SQLException::class)
    val connection: Connection?
        /*** 获取数据库的连接对象 * @return * @throws SQLException  */
        get() {
            //为了让整个应用程序有且只有一个数据库连接对象 ---单例模式
            if (conn == null || conn!!.isClosed) {
                conn = DatabaseManager.connection
            }
            return conn
        }

    @Throws(SQLException::class)
    fun closeConnection(conn: Connection?) {
        conn?.close()
    }
}
